﻿using System;
using System.Net;
using System.Windows;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Api.ContentProvider;
using System.Collections.Generic;

namespace DefaultContentProvider
{
    public class CompositeContentProvider : IContentProvider
    {
        private IEnumerable<IContentProvider> contentProviderCollection;

        public CompositeContentProvider(IEnumerable<IContentProvider> contentProviderCollection)
        {
            this.contentProviderCollection = contentProviderCollection;
        }

        public bool IsItemTypeSupported(string itemType)
        {
            if (itemType == null)
            {
                throw new ArgumentNullException("itemType");
            }

            foreach (var contentProvider in contentProviderCollection.Where(content => content.IsItemTypeSupported(itemType)))
            {
                return true;
            }

            return false;
        }

        public Func<string, UIElement> GetItemsMapping(string itemType)
        {
            if (itemType == null)
            {
                throw new ArgumentNullException("itemType");
            }

            foreach (var contentProvider in contentProviderCollection.Where(content => content.IsItemTypeSupported(itemType)))
            {
                return contentProvider.GetItemsMapping(itemType);
            }

            throw new KeyNotFoundException();
        }
    }
}
